home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 740 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.0 KB

  1. From: ebiederm@cse.unl.edu (Eric W. Biederman)
  2. Message-ID: <ERIC.96Mar15153848@cse.unl.edu>
  3. X-Original-Date: 15 Mar 1996 21:38:48 GMT
  4. Path: in1.uu.net!bounce-back
  5. Date: 16 Mar 96 10:13:46 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: Exception handling -- was a finally block ever considered?
  9. Organization: University of Nebraska--Lincoln    
  10. References: <31475017.8100207@nntp.ix.netcom.com>
  11. In-Reply-To: jdmorris@ix.netcom.com's message of 13 Mar 96 23:50:08 GMT
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBFAgUBMUqUZ+EDnX0m9pzZAQHHCwF/WbETwMaD5RbtsuQm4NRdlxK3L9fOGY/P
  14.     E4DAJg0WRVNwI2OqQVwe/jRDP7FIBFRg
  15.     =ODJ4
  16.  
  17. In article <31475017.8100207@nntp.ix.netcom.com> jdmorris@ix.netcom.com
  18. (Jason D. Morris) writes:
  19.  
  20.    I would like to know if the following construct was ever considered by
  21.    the C++ and if it was, why it was rejected.
  22.  
  23.    try
  24.    {
  25.        // some code that could generate an exception...
  26.    }
  27.    catch ( // some expected exception type )
  28.    {
  29.        // handler code
  30.    }
  31.    finally
  32.    {
  33.        // code that would be guaranteed to execute no matter how the 
  34.        // function was exited.
  35.    }
  36.  
  37. This can be written quite easily as I see it with C++, though the
  38. structure is a little awkward. 
  39.  
  40. Basically you just need to write a destructor.  The code ordering is a
  41. little less pleasant 
  42. Say,
  43.  
  44. func( ... )
  45. {
  46.    class finally{
  47.    public:
  48.    ~finally()
  49.    {
  50.        // code that would be guaranteed to execute no matter how the 
  51.        // function was exited.
  52.    } finally;
  53.    try
  54.    {
  55.        // some code that could generate an exception...
  56.    }
  57.    catch ( // some expected exception type )
  58.    {
  59.        // handler code
  60.    }
  61. }
  62. ---
  63. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  64. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  65. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  66. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  67. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  68.